<?php
/**
 * @version     1.0.0
 * @package     com_geotrails
 * @copyright   Copyright (C) 2011. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 * @author      Verbier Technologies Sarl
 */

/**
 * @param	array	A named array
 * @return	array
 */
function GeotrailsBuildRoute(&$query) {

	$segments = array();
	
	if (isset($query['id'])) {
		$segments[] = $query['id'];
		unset( $query['id'] );
	}
	
	if (isset($query['view'])) {
	
		if (empty($query['Itemid'])) {
			$segments[] = $query['view'];
		}
	
		unset($query['view']);
	}
	
	if (isset($query['task'])) {
		$segments[] = $query['task'];
		unset($query['task']);
	}

	if (isset($query['format'])) {
		$segments[] = $query['format'];
		unset($query['format']);
	}

	if (isset($query['layout'])) {
		$segments[] = $query['layout'];
		unset($query['layout']);
	}	
		
	return $segments;
}

/**
 * @param	array	A named array
 * @param	array
 *
 * Formats:
 *
 * index.php?/banners/task/id/Itemid
 * index.php?/banners/id/Itemid
 */
function GeotrailsParseRoute($segments) {

	$application = JFactory::getApplication();
	$menu	     = $application->getMenu();
	$active	     = $menu->getActive();
	
	$vars = array();

	$id = explode( ':', $segments[0] );
	
	$vars['id']   = (int) $id[0];
	$vars['view'] = 'fiche';
	
	if (in_array('feed', $segments)) {
		$vars['view'] = 'geotrails' ;
		$vars['format'] = 'feed' ;
	}

	if (in_array('default_map_zoom', $segments)) {
		$vars['view'] = 'maps' ;
		$vars['format'] = 'raw' ;
		$vars['layout'] = 'default_map_zoom' ;
	}	
	
	return $vars;
}